package cz.zcu.fav.rat.beans;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import org.hibernate.search.annotations.Analyze;
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.Store;


@Indexed
public class Object implements Serializable, Indexable
{	
	private static final long serialVersionUID = -4204980189607846673L;
	
	private Integer id;
	private String identifier;
	private String name;
	private String description;
	private Set<Reservation> reservations = new HashSet<Reservation>();
	private ObjectClass objectClass;

	public ObjectClass getObjectClass()
	{
		return objectClass;
	}

	public void setObjectClass(ObjectClass objectClass)
	{
		this.objectClass = objectClass;
	}
	
	@DocumentId
	public Integer getId()
	{
		return id;
	}

	public void setId(Integer id)
	{
		this.id = id;
	}

	public String getIdentifier()
	{
		return identifier;
	}

	public void setIdentifier(String identifier)
	{
		this.identifier = identifier;
	}

	@Field(index = Index.YES, analyze = Analyze.YES, store = Store.NO)
	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

    @Field(index = Index.YES, analyze = Analyze.YES, store = Store.NO)
	public String getDescription()
	{
		return description;
	}

	public void setDescription(String description)
	{
		this.description = description;
	}

	public Set<Reservation> getReservations()
	{
		return reservations;
	}

	public void setReservations(Set<Reservation> reservations)
	{
		this.reservations = reservations;
	}
	
	public void addReservation(Reservation reservation)
	{
		this.reservations.add(reservation);
	}

	@Override
	public int hashCode()
	{
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((description == null) ? 0 : description.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result
				+ ((identifier == null) ? 0 : identifier.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(java.lang.Object obj)
	{
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Object other = (Object) obj;
		if (description == null)
		{
			if (other.description != null)
				return false;
		} else if (!description.equals(other.description))
			return false;
		if (id == null)
		{
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (identifier == null)
		{
			if (other.identifier != null)
				return false;
		} else if (!identifier.equals(other.identifier))
			return false;
		if (name == null)
		{
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}


	
	
}
